package com.awei.study.design.found.prototype;

import java.io.Closeable;

/**
 * 原型模式
 */
public class ClonePrototype implements Cloneable {

    private Prototype prototype;


    public Prototype getPrototype() {
        return prototype;
    }

    public void setPrototype(Prototype prototype) {
        this.prototype = prototype;
    }

    @Override
    protected ClonePrototype clone() throws CloneNotSupportedException {
        return (ClonePrototype)super.clone();
    }

    public static void main(String[] args) throws CloneNotSupportedException {
        ClonePrototype c1 = new ClonePrototype();
        Prototype p1 = new Prototype();
        p1.setType("原型");
        c1.setPrototype(p1);
        ClonePrototype c2 = c1.clone();
        Prototype p2 = c2.getPrototype();
        p2.setType("克隆");


        System.out.println(p1.equals(p2));
        System.out.println(p1.getType());
    }
//    static class ClonePrototypeTest {
//        public static void main(String[] args) throws CloneNotSupportedException {
//            ClonePrototype c1 = new ClonePrototype();
//            ClonePrototype c2 = c1.clone();
//            System.out.println(c1 == c2);
//        }
//    }
}
